const {
	editUrl,
	listUrl,
	listUserUrl,
	otherUserUrl,
} = require('@utils/util-apis')['bugUrl']
const {
	showDetail,
} = require('./bug-methods')

module.exports = function() {
	let {
		bugComp,
	} = $['components-jq']
	bugComp.dailogComp = {
		formDialog: $("#bug-form-dialog")
	}
	bugComp.dataGrid = $("#bug-table")
	bugComp.form = $("#bug-form")
	bugComp.projectName = $("#bug-form-project")
	bugComp.projectVersion = $("#bug-form-version")
	bugComp.createUser = $("#bug-form-user")
	bugComp.createDate = $("#bug-form-date")
	bugComp.desc = $("#bug-form-desc")
	initDataGrid(bugComp)
	initDialog(bugComp)
}

function initDataGrid(bugComp) {
	let {
		form,
		dataGrid,
		dailogComp,
	} = bugComp
	let formDialog = dailogComp.formDialog
	dataGrid.datagrid({
		fit: true,
		url: listUrl,
		rownumbers: true,
		fitColumns: true,
		singleSelect: true,
		toolbar: [{
			iconCls: 'icon-search',
			text: '查看详情',
			handler() {
				showDetail.call(bugComp)
			}
		}],
		columns: [
			[{
				field: 'id',
				title: 'ID',
				width: 5
			}, {
				field: 'project_name',
				title: '项目名称',
				width: 20
			}, {
				field: 'project_version',
				title: '版本号',
				width: 15,
			}, {
				field: 'create_date',
				title: '创建时间',
				width: 20,
			}, {
				field: 'create_user',
				title: '创建人',
				width: 20,
			}]
		],
		onDblClickRow(index, row) {
			showDetail.call(bugComp, index, row)
		},
	})
}

function initDialog(bugComp) {
	let {
		dailogComp,
	} = bugComp
	let formDialog = dailogComp.formDialog
	formDialog.dialog({
		title: '提交BUG/建议',
		top: 50,
		left: 240,
		width: 800,
		height: 560,
		closed: true,
		modal: true,
	})
}